package com.yundong.gongchengji.ui.my.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.yundong.gongchengji.R;
import com.yundong.gongchengji.adapter.MyPagerAdapter;
import com.yundong.gongchengji.base.BaseActivity;
import com.yundong.gongchengji.base.BaseFragment;
import com.yundong.gongchengji.ui.my.fragment.TaskMessageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的信息
 * Created by ls on 2017/2/21.
 */

public class MyMessageActivity extends BaseActivity {
    private TabLayout tabMymessageTitle;
    private ViewPager viewpageMessagefragment;
    //创建一个标题集合
    private List<String> title_list=new ArrayList<String>();
    //fragment集合
    private List<BaseFragment>fragment_list=new ArrayList<BaseFragment>();
    @Override
    public int getContentViewId() {
        return R.layout.activity_my_message;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setLeft();
        setTitle("我的消息");
        tabMymessageTitle= (TabLayout) findViewById(R.id.tab_mymessage_title);
        viewpageMessagefragment= (ViewPager) findViewById(R.id.viewpage_messagefragment);
    }

    @Override
    protected void initVariable() {
        title_list.add("任务消息");
        title_list.add("系统消息");
        title_list.add("留言消息");
        fragment_list.add(new TaskMessageFragment());
        fragment_list.add(new TaskMessageFragment());
        fragment_list.add(new TaskMessageFragment());
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        tabMymessageTitle.setTabMode(TabLayout.MODE_FIXED);
        tabMymessageTitle.addTab(tabMymessageTitle.newTab().setText(title_list.get(0)));
        tabMymessageTitle.addTab(tabMymessageTitle.newTab().setText(title_list.get(1)));
        tabMymessageTitle.addTab(tabMymessageTitle.newTab().setText(title_list.get(2)));
        viewpageMessagefragment.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragment_list.get(position);
            }

            @Override
            public int getCount() {
                return fragment_list.size();
            }
        });
        MyPagerAdapter adapter=new MyPagerAdapter(getSupportFragmentManager(),title_list,fragment_list);
        viewpageMessagefragment.setAdapter(adapter);
        tabMymessageTitle.setupWithViewPager(viewpageMessagefragment);
    }
}
